package com.log4jviewer.ui.preferences.filters;

import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.junit.Test;

/**
 * 
 * @author <a href="mailto:Daniil.Yaroslavtsev@gmail.com"> Daniil Yaroslavtsev </a>
 * 
 */
public class TablesEditingTraverseTest extends AbstractFiltersPageTest {

    private FilterSettings filterSettings = FilterPreferencePage.getFilterSettings();

    private TableViewer filterSettingsViewer = filterSettings.getTableViewer();

    /**
     * Tests that Filter Table edit and editor traversing are works well (ENABLE_COLUMN can`t be traversed).
     * 
     * @throws InterruptedException
     */
    @Test
    public void testFilterTableEditTraversing() throws InterruptedException {

        addFilters(2);

        getFilterTable().click(0, 0);

        // start editing a first cell
        getFilterTable().pressShortcut(getKey(SWT.F2));
        waitForCellEditorState(filterSettingsViewer, true);
        getFilterTable().getTableItem(0).pressShortcut(getKey(SWT.TAB));
        waitForCellEditorState(filterSettingsViewer, true);
        getFilterTable().getTableItem(0).pressShortcut(getKey(SWT.TAB));
        waitForCellEditorState(filterSettingsViewer, true);
        // Write "a" in cell (1,0);
        getFilterTable().getTableItem(1).pressShortcut(getKey(49));

        // stop cell editing (saving a new cell value - "a")
        getAddFilterButton().setFocus();

        String cellText = getFilterTable().cell(1, 0);

        assertEquals(cellText, "1");
    }

}
